package com.jusyl.cristo.spider.lianjia.schduler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.jusyl.cristo.spider.lianjia.WebMagicLianJia;

import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.pipeline.Pipeline;

// @Component
public class LianJiaErShouFangTask {
	
	@Autowired
	@Qualifier("abc")
	private Pipeline lianJiaPipeline;
	
	//@Scheduled(cron="0/20 * *  * * ? ")   //每10小时执行一次 
	public void task() {
		System.out.println("开始执行定时任务");
		System.out.println(lianJiaPipeline == null);
		if(lianJiaPipeline == null) {
			System.out.println(true);
		}else {
			System.out.println(false);
		}
		
		try {
//			Spider.create(new WebMagicLianJia())
//			.addPipeline(lianJiaPipeline)
//			.addUrl("https://bj.lianjia.com/ershoufang/rs%E4%B8%89%E7%8E%AF%E6%96%B0%E5%9F%8E/")
//			.thread(5).run();
			Spider.create(new WebMagicLianJia())
			.addPipeline(lianJiaPipeline)
			.addUrl("https://bj.lianjia.com/ershoufang/pg/")
			.thread(5).run();
		}catch(Exception e) {
			e.printStackTrace();
		}
	}

	public Pipeline getLianJiaPipeline() {
		return lianJiaPipeline;
	}

	public void setLianJiaPipeline(Pipeline lianJiaPipeline) {
		this.lianJiaPipeline = lianJiaPipeline;
	}
}
